import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
from selenium.webdriver.support.select import Select
testCase="DBshop006_删除取消订单流程"

# 查看已存取消订单号
rootpath=get_pro_rootpath()
orderID=readFile(rootpath+r".\public\order004.txt")
# 1.点击销售管理订单管理界面。
firefox=openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,"销售管理","订单管理")
# 2.在订单状态点击已取消一栏，点击“搜索”按钮一款，勾选之后，选择删除，点击提交操作。
# 查看订单总数
str1=firefox.find_element_by_xpath("//div[@style='height: 30px; border-bottom: 4px solid #DFDFDF;']").text
l="订单数："
r="\)"
num1=reGetString(str1,l,r)
# 查看已取消订单
select=firefox.find_element_by_id("order_state")
s=Select(select)
s.select_by_visible_text("已取消")
firefox.find_element_by_xpath("//button[@class='btn btn-small btn-primary']").click()
# 删除取消的订单
firefox.find_element_by_xpath("//td[text()='%s']/following-sibling::td[7]/a"%orderID).click()
firefox.find_element_by_link_text("删除订单").click()
firefox.switch_to_alert().accept()
# 断言
str2=firefox.find_element_by_xpath("//div[@style='height: 30px; border-bottom: 4px solid #DFDFDF;']").text
num2=reGetString(str2,l,r)
try:
    if int(num2)==int(num1)-1:
        writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()
